package com.example.c94s3plyhyfc;

import com.example.c94s3plyhyfc.web.LoginIntercepter;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

import javax.annotation.Resource;

@SpringBootApplication
@MapperScan("com.example.c94s3plyhyfc.mapper")
// 开启定时任务
@EnableScheduling
// 要注册 SpringMVC 的拦截器, SpringBoot主类必须实现 WebMvc配置接口
public class C94S3PlyHyfcApplication implements WebMvcConfigurer {

    public static void main(String[] args) {
        SpringApplication.run(C94S3PlyHyfcApplication.class, args);
    }

    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }

    /**
     * 注册拦截器方法
     * InterceptorRegistry registry 拦截器的注册器
     */
    @Resource
    LoginIntercepter loginIntercepter;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginIntercepter)
                // 定义要拦截的目标资源路径
                .addPathPatterns("/bbs_edit.html","/bbs/save");
    }
}
